package DAO;

import hibernate.HibernateUtil;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import clases.Mascota;
import clases.Veterinario;

public class VeterinarioDAO {

	SessionFactory factory;
	
	public VeterinarioDAO(){
		
		factory= HibernateUtil.getSessionFactory();
	}
	
	public void saveOrUpdate(Veterinario vet) {
		
		Session session=factory.openSession();
		Transaction tx=session.beginTransaction();
		session.saveOrUpdate(vet);
		tx.commit();
		session.close();
	}
	
	
	public void delete(Veterinario vet) {
		Session session=factory.openSession();
		Transaction tx=session.beginTransaction();
		session.delete(vet);
		tx.commit();
		session.close();
	}
	
	public Veterinario findMas(int id){
		
		Session session= factory.openSession();
		Query q= session.createQuery("from Veterinario v where v.doc="+id);
		Veterinario tmp=(Veterinario)q.uniqueResult();
		return tmp;
	}
	
	public List<Veterinario> findAll(){
		
		Session session= factory.openSession();
		Query q= session.createQuery("from Veterinario");
		List<Veterinario> p = q.list();
		return p;
	}

}
